package main

import (
	"net"

	"gitcode.com/shexk/fimq/core"
)

type Fimq struct {
	server *core.TcpServer
}

func NewFimq() *Fimq {
	return &Fimq{}
}
func (s *Fimq) StartServer(port int) error {
	s.server = core.NewTcpServer(port, ServerCallback, nil)
	if err := s.server.Start(); err != nil {
		println("Error starting server:", err.Error())
		return err
	}

	core.GetTopicMng().LoadAllTopicsInfoFromDB()
	core.GetBroker().StartProcessTask()
	return nil
}
func ServerCallback(ref interface{}, conn net.Conn, state int, err error, data []byte, datasize uint32) {
	core.GetBroker().ProcessData(ref, conn, state, err, data, datasize)
}
